package com.meihua.shellapp.activity.set;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.meihua.shellapp.R;
import com.meihua.shellapp.activity.AuthenticationInfoActivity;
import com.meihua.shellapp.adapter.personalcenter.AccountSecurityAdapter;
import com.meihua.shellapp.base.BaseActivity;
import com.meihua.shellapp.base.MyApplication;
import com.meihua.shellapp.dialog.BaseMessageDialog;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;


public class AccountSecurityActivity extends BaseActivity {

    @Bind(R.id.lv_account_security)
    ListView lv_account_security;//账户与安全适配器
    @Bind(R.id.iv_top_left)
    ImageView iv_top_left;//返回
    @Bind(R.id.tv_title)
    TextView tv_title;//标题

    private AccountSecurityAdapter adapter;//帐号与安全板块适配器
    private List<String> mDataStr;//显示板块的字
    private List<String> mDataValueStr;//板块字后跟的值
    private BaseMessageDialog dialog;

    @Override
    public int getLayoutId() {
        return R.layout.activity_account_security;
    }

    @Override
    public void initView(Bundle savedInstanceState) {
        iv_top_left.setVisibility(View.VISIBLE);
        tv_title.setVisibility(View.VISIBLE);
        tv_title.setText("账户与安全");
        iv_top_left.setOnClickListener(this);
    }

    @Override
    protected void onResume() {
        super.onResume();
        initData();
    }

    /**
     * 加载数据
     */
    private void initData() {
        mDataStr = new ArrayList<>();
        mDataStr.add("修改手机号");
        mDataStr.add("修改登录密码");
        if (MyApplication.getInstance().bean.getIspay_pwd().equals("0"))
            mDataStr.add("设置支付密码");
        else
            mDataStr.add("找回支付密码");
        mDataValueStr = new ArrayList<>();
        mDataValueStr.add(MyApplication.getInstance().bean.getPhone().substring(0, 3) + "****" + MyApplication.getInstance().bean.getPhone().substring(7, 11));
        mDataValueStr.add("");
        mDataValueStr.add("");
        adapter = new AccountSecurityAdapter(mContext, mDataStr, mDataValueStr);
        lv_account_security.setAdapter(adapter);
        lv_account_security.setOnItemClickListener(mItemClick);
    }

    private AdapterView.OnItemClickListener mItemClick = new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            Intent in = new Intent();
            switch (i) {
                case 0://修改手机号  1,注册;2.登录;3找回密码;4.修改手机号 新手机号;5修改支付密码;6.修改手机号 旧手机号’
                    in.setClass(AccountSecurityActivity.this, AuthenticationInfoActivity.class);
                    in.putExtra("type", 6);
                    startActivity(in);
                    break;
                case 1://更改登录密码
                    in.setClass(AccountSecurityActivity.this, ChangePasswordActivity.class);
                    startActivity(in);
                    break;
                case 2://支付密码
                    if (MyApplication.getInstance().bean.getIspay_pwd().equals("0")) {
//                        ToastUtils.getInstance().showToast("设置支付密码");
                        in.setClass(mContext, VerificatoinCardActivity.class);
                        startActivity(in);
                    } else {
                        dialog = new BaseMessageDialog.Builder(mContext)
                                .setClickSure(new View.OnClickListener() {
                                    @Override
                                    public void onClick(View view) {
                                        goRememberPwd();
                                        dialog.dismiss();
                                    }
                                })
                                .setClickCencle(new View.OnClickListener() {
                                    @Override
                                    public void onClick(View view) {
                                        goForgetPwd();
                                        dialog.dismiss();
                                    }
                                })
                                .setMessage("您是否记得帐号" + MyApplication.getInstance().bean.getPhone().substring(0, 3) + "****" + MyApplication.getInstance().bean.getPhone().substring(7, 11)
                                        + "当前使用的支付密码")
                                .show()
                                .setCencleStr("不记得")
                                .setSureStr("记得");
                    }
                    break;
            }
        }
    };

    /**
     * 记得密码动作
     */
    public void goRememberPwd() {
        Intent in = new Intent(mContext, VerificatoinPayPwdActivity.class);
        startActivity(in);
    }

    /**
     * 忘记密码动作
     */
    public void goForgetPwd() {
        Intent in = new Intent(mContext, VerificatoinCardActivity.class);
        startActivity(in);
    }
}
